package com.ianswer.px.user.service.impl;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.ianswer.common.orm.PublicDao;
import com.ianswer.px.user.entity.UsersEdu;
import com.ianswer.px.user.service.UsersEduService;

@Service("usersEduService")
public class UsersEduServiceImpl implements UsersEduService {
	
	@Resource(name = "publicDao")
	private PublicDao publicDao;

	@Override
	public void save(UsersEdu edu) {
		UsersEdu db = query(edu.getUserId());
		if (db == null) {
			insert(edu);
		} else {
			update( edu);
		}
	}
	
	@Override
	public void insert(UsersEdu edu) {
		publicDao.insert("usersEdu.insert", edu);
	}
	
	@Override
	public void update(UsersEdu edu) {
		publicDao.update("usersEdu.update", edu);
	}

	@Override
	public UsersEdu query(long userId) {
		return publicDao.querySingle("usersEdu.get", userId);
	}
	
	@Override
	public UsersEdu get(long userId) {
		UsersEdu r = query(userId);
		if (r != null) {
			if (StringUtils.isEmpty(r.getUniversity()) &&
				StringUtils.isEmpty(r.getTrain1()) &&
				StringUtils.isEmpty(r.getTrain2()) &&
				StringUtils.isEmpty(r.getTrain3()) &&
				StringUtils.isEmpty(r.getTrain4()) &&
				StringUtils.isEmpty(r.getTrain5())) {
				return null;
			}
		}
		return r;
	}

}
